/**
 * router 控制页面跳转
 * 在这里配置页面跳转参数
 * 
 * @authors YangSh
 * @date    2017-4-19
 * @version 0.0.1
 */
//路由跳转
define(['app',
    'view/bookMain/bookMainCtrl',
    'view/count/countCtrl',
    'view/login/login.ctrl',
    'view/borrowerMngr/list/borrowerMngrCtrl',
    'view/borrowerMngr/edit/BorrowerMngrEditCtrl',
    'view/infoMngr/list/bookInfoMngrCtrl',
    'view/infoMngr/model/bookInfoMngrAddModelCtrl',
    'view/note/list/bookNoteCtrl',
    'view/note/model/bookNoteModelCtrl',
    'view/classify/list/bookClassifyCtrl',
     'view/classify/model/bookClassifyModelCtrl',
    'view/demo/form/formCtrl',
    'view/demo/grid/tableCtrl',
    'view/borrower/list/borrowerController',
    'view/borrower/edit/borrowerEditController',
    'view/templet/selectBorrowerController',
    'view/templet/selectBook/selectBookController'
], function (app) {
    'use strict';
    app.config(function ($stateProvider, $urlRouterProvider) {
        //$urlRouterProvider.otherwise('/suggestion/propose');
        $urlRouterProvider.otherwise('/book/main');
        $stateProvider
            .state('login', {
                url: '/login',
                views: {
                    '': {
                        templateUrl: 'app/view/login/login.tpl.html'
                    }
                }
            })
            .state('book', {
                url: '/book',
                views: {
                    '': {
                        templateUrl: 'app/view/dashboard.html'
                    }
                }
            })

            //首页      
           .state('book.main', {
               url: '/main',
               views: {
                   'main': {
                       templateUrl: 'app/view/bookMain/bookMain.html',
                       controller: 'BookMainCtrl'
                   }
               }
           })
           //图书信息统计
           .state('book.count', {
               url: '/count',
               views: {
                   'main': {
                       templateUrl: 'app/view/count/count.html',
                       controller: 'CountCtrl'
                   }
               }
           })
            //demo
            .state('book.demo', {
                url: '/demo',
                views: {
                    'main': {
                        templateUrl: 'app/view/demo/demoview.html'
                    }
                }
            })
            .state('book.demo.grid', {
                url: '/grid',
                views: {
                    'demoView': {
                        templateUrl: 'app/view/demo/grid/tables.html'
                    }
                }
            })
            .state('book.demo.form', {
                url: '/form',
                views: {
                    'demoView': {
                        templateUrl: 'app/view/demo/form/form.html',
                        controller: 'FormCtrl'
                    }
                }
            })
            //图书借阅管理
            .state('book.borrowerMngr', {
                url: '/borrowerMngr',
                views: {
                    'main': {
                        templateUrl: 'app/view/borrowerMngr/borrowerMngrView.html'
                    }
                }
            })
            .state('book.borrowerMngr.list', {
                url: '/list',
                views: {
                    'borrowerMngrview': {
                        templateUrl: 'app/view/borrowerMngr/list/borrowerMngr.html',
                        controller: 'borrowerMngrCtrl'
                    }
                }
            })
            .state('book.borrowerMngr.edit', {
                url: '/edit',
                views: {
                    'borrowerMngrview': {
                        templateUrl: 'app/view/borrowerMngr/edit/borrowerMngrEdit.html',
                        controller: 'BorrowerMngrEditCtrl'
                    }
                }
            })
            //图书信息管理
            .state('book.infoMngr', {
                url: '/infoMngr',
                views: {
                    'main': {
                        templateUrl: 'app/view/infoMngr/mngrView.html'
                    }
                }
            })
            .state('book.infoMngr.list', {
                url: '/list',
                views: {
                    'mngrview': {
                        templateUrl: 'app/view/infoMngr/list/bookInfoMngr.html',
                        controller: 'BookInfoMngrCtrl'
                    }
                }
            })
            .state('book.infoMngr.edit', {
                url: '/model:id/:type',
                views: {
                    'mngrview': {
                        templateUrl: 'app/view/infoMngr/model/bookInfoMngrAddModel.html',
                        controller: 'BookInfoModelCtrl'
                    }
                }
            })
            //图书分类管理
            .state('book.classify', {
                url: '/classify',
                views: {
                    'main': {
                        templateUrl: 'app/view/classify/classifyView.html'
                    }
                }
            })
            .state('book.classify.list', {
                url: '/list',
                views: {
                    'classifyview': {
                        templateUrl: 'app/view/classify/list/bookClassify.html',
                        controller: 'BookClassifyCtrl'
                    }
                }
            })

            //阅读笔记管理
            .state('book.note', {
                url: '/note',
                views: {
                    'main': {
                        templateUrl: 'app/view/note/noteView.html'
                    }
                }
            })
            .state('book.note.list', {
                url: '/list',
                views: {
                    'noteview': {
                        templateUrl: 'app/view/note/list/bookNote.html',
                        controller: 'BookNoteCtrl'
                    }
                }
            })
            .state('book.note.edit', {
                url: '/model:id/:type',
                views: {
                    'noteview': {
                        templateUrl: 'app/view/note/model/bookNoteModel.html',
                        controller: 'BookNoteModelCtrl'
                    }
                }
            })

       //借阅人管理
       .state('book.borrower', {
           url: '/borrower',
           views: {
               'main': {
                   templateUrl: 'app/view/borrower/borrowerview.html'
               }
           }
       })
       .state('book.borrower.list', {
           url: '/list',
           views: {
               'uiView': {
                   templateUrl: 'app/view/borrower/list/borrower.html',
                   controller: 'borrowerController'
               }
           }
       })
       .state('book.borrower.edit', {
           url: '/edit:id',
           views: {
               'uiView': {
                   templateUrl: 'app/view/borrower/edit/borrowerEdit.html',
                   controller: 'borrowerEditController'
               }
           }
       })
        ;
    });
    // 禁止模板缓存  
    app.run(function ($rootScope, $templateCache) {
        $rootScope.$on('$routeChangeStart', function (event, next, current) {
            if (typeof (current) !== 'undefined') {
                $templateCache.remove(current.templateUrl);
            }
        });
    });

    return app;
});